/*******************************************************************************
 * LineWrap.cpp
 * Author: Andrew Shore
 * Date Last Modified: 26 March 2010
 *
 * This function consists of a constructor, destructor, and a single function
 * checkLineWrap(). checkLineWrap() is called in the main function to see
 * if a file has any lines wrapped.
 *
 ******************************************************************************/

#include "LineWrap.h"

/*******************************************************************************
 * Constructor
 ******************************************************************************/
LineWrap::LineWrap(){
}
/*******************************************************************************
 * Destructor
 ******************************************************************************/
LineWrap::~LineWrap(){
}

/*******************************************************************************
 * Checks to see if a file has any lines wrapped.
 * Author: Andrew Shore
 * Date Last Modified: 26 March 2010
 *
 * This function gets the first 120 characters of a line set by the enumerated
 * constant MAX_SIZE.  If there are more than 80 characters in the line then
 * it is wrapped. If the line is wrapped function displays how many characters
 * are in the line and displays the line itself. Function also displays the
 * total number of lines wrapped.
 *
 * Parameters: 
 *  ifstream& inputStream - stream for the file to be line checked
 *  string fileName - name of the file used for displaying purposes
 *
 * Output: log of information of lines that are wrapped
 *
 * Returns: none
 ******************************************************************************/
void LineWrap::checkLineWrap(ifstream& inputStream, string fileName){

  /************
    Variables:
      line - string version of line
      lineArray - char array used in getline function then copied to string line
      lineCount - current line number, intialized to 1
      lineWrapCount - count of how many lines are wrapped
  **/
  string line;
  char lineArray[MAX_SIZE];
  int lineCount = 1;
  int lineWrapCount = 0;
  
  cout << "Checking " << fileName << " for line wrap:\n";

  while( !inputStream.eof() ){
    inputStream.getline( lineArray, MAX_SIZE);
    line = lineArray;
    
    if( line.size() > MAX_LINE_LENGTH ){
      inputStream.clear();
      

      if( line.size() == MAX_SIZE - 1){
        //if the line is larger than the maximum size of the char array this 
	//gets the rest of the line
        inputStream.getline( lineArray, MAX_SIZE);
        line += lineArray;
      }
      cout << "line " << lineCount << " is wrapped: line is " 
           << line.size() << " characters long\n"; 
       
      cout << "     " << line << endl;
      lineWrapCount++;
    }
    lineCount++;
  }//while( !inputStream.eof() )
  
  cout << "There are a total of " << lineWrapCount 
       << " lines wrapped in this file\n\n\n";

}//void LineWrap::checkLineWrap(ifstream& inStream, string fileName)
